---
category: Math
created: '2021-04-08'
title: Calculate the angle of a line defined by two points
updated: '2021-10-13'
---

**JavaScript version**

```js radiansAngle.js
// In radians
const radiansAngle = (p1, p2) => Math.atan2(p2.y - p1.y, p2.x - p1.x);

// In degrees
const degreesAngle = (p1, p2) => (Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180) / Math.PI;
```

**TypeScript version**

```ts radiansAngle.ts
interface Point {
    x: number;
    y: number;
}

const radiansAngle = (p1: Point, p2: Point): number => Math.atan2(p2.y - p1.y, p2.x - p1.x);

const degreesAngle = (p1: Point, p2: Point): number => (Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180) / Math.PI;
```
